package com.bang.study.esl.controller;

import com.alibaba.fastjson.JSONObject;
import com.bang.study.esl.model.EslClient;
import org.freeswitch.esl.client.transport.event.EslEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.CompletableFuture;

/**
 * @Auther: Bang
 * @Date: 2019/9/6 0006 16:40
 * @Description:
 */
@RequestMapping
@Component
public class EslController {

    private static Logger logger = LoggerFactory.getLogger(EslController.class);

    @Autowired
    private EslClient eslClient;

    @RequestMapping("/")
    @ResponseBody
    public String handler() {
        String list_users = "list_users";
        String sofia_contact = "sofia_contact user/admin20";
        String originate = "originate user/admin20 &echo";

        CompletableFuture<EslEvent> backgroundApiCommand = eslClient.sendBackgroundApiCommand(originate, null);
        System.err.println(JSONObject.toJSONString(backgroundApiCommand));
//
//        EslMessage message = eslClient.sendSyncApiCommand(originate, null);
//        String contentType = message.getContentType();
//        logger.error(JSONObject.toJSONString(message));
//        logger.error("ContentType: {}", contentType);
//        List<String> bodyLines = message.getBodyLines();
//        for (String bodyLine : bodyLines) {
//            System.out.println(bodyLine);
//        }
        return "success";

    }
}
